﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ChinaGS.Lian.ModuleRemoting;

public partial class pay_express_fill_power : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SysCommon.checkUserLogin();

        if (!IsPostBack)
        {
            String MNBR = Request["HidMNBR"];
            String NOSA = Request["HidNOSA"];
            String PDTA = Request["HidPDTA"];
            String PNBR = Request["HidPNBR"];
            String PPNO = Request["HidPPNO"];
            String PSNO = Request["HidPSNO"];
            String PWNO = Request["HidPWNO"];
            String SSMN = Request["HidSSMN"];
            String USAD = Request["HidUSAD"];
            String USNM = Request["HidUSNM"];
            String USNO = Request["HidUSNO"];
            String WNBR = Request["HidWNBR"];

            String cusNo = Request["HidCusNo"];
            String NowMoney = Request["HidNowMoney"];
            String PreMoney = Request["HidPreMoney"];
            String PayMoney = Request["HidPayMoney"];


            if (Request["HidMNBR"] != null)
            {

                LabNowMoney.Text = NowMoney;
                LabPayMoney.Text = PayMoney;
                LabPreMoney.Text = PreMoney;


                LabMNBR.Text = MNBR;
                LabNOSA.Text = NOSA;
                LabPDTA.Text = PDTA;
                LabPNBR.Text = PNBR;
                LabPPNO.Text = PPNO;
                LabPSNO.Text = PSNO;
                LabPWNO.Text = PWNO;
                LabSSMN.Text = SSMN;
                LabUSAD.Text = USAD;
                LabUSNM.Text = USNM;
                LabUSNO.Text = USNO;
                LabWNBR.Text = WNBR;

                    HidMNBR.Value = MNBR;
                    HidNOSA.Value = NOSA;
                    HidPDTA.Value = PDTA;
                    HidPNBR.Value = PNBR;
                    HidPPNO.Value = PPNO;
                    HidPSNO.Value = PSNO;
                    HidPWNO.Value = PWNO;
                    HidSSMN.Value = SSMN;
                    HidUSAD.Value = USAD;
                    HidUSNM.Value = USNM;
                    HidUSNO.Value = USNO;
                    HidWNBR.Value = WNBR;
                    HidCusNo.Value = cusNo;
                    HidNowMoney.Value = NowMoney;
                    HidPreMoney.Value = PreMoney;

                    PanPay.Visible = true;

            }
            else
            {
                PanPay.Visible = false;
                this.LabMessage.Text = "操作失败，请重试！";

            }

        }
    }
    protected void NextStep_Click(object sender, EventArgs e)
    {        
        //充值前操作            
        int user_paid_id = DataBaseOperate_SQLServer.execPPaidAtonce(Session["user_id"].ToString(), "5".ToString(), HidCusNo.Value, 
                TexPayMoney.Text, TexPayMoney.Text, "0".ToString(), "0".ToString(), "0".ToString(), System.DateTime.Now.ToString(), "none".ToString());

            if (user_paid_id < 0)
            {
                LabMessage.Text = "操作失败！原因是：" + RemotingClass.alertExecErroeResult(user_paid_id).ToString() + "，请重试";
                PanPay.Visible = false;
            }
            else {

                PowerPackage pp = RemotingClass.powerPayMoney(HidCusNo.Value, System.Convert.ToDouble(TexPayMoney.Text), System.Convert.ToDouble(HidPreMoney.Value), System.Convert.ToDouble(HidNowMoney.Value), HidPNBR.Value, System.Convert.ToDouble(HidMNBR.Value), System.Convert.ToDouble(HidWNBR.Value));
                //测试
                /*PowerPackage pp = new PowerPackage();
                pp.Status = true;
                pp.SerialNo = "123456789";
                pp.Message = "success";
                pp.StatusNo = "00";
                pp.PayMoney = 100;
                pp.PreMoney = 1;
                pp.NowMoney = 2;
                PowerBill pb1 = new PowerBill();
                pb1.PNBR = "123456789";
                pb1.PDTA = "20110712";
                pb1.MNBR = "100";
                pb1.WNBR = "10";
                pb1.USNM = "denver";
                pb1.USAD = "qd";
                pb1.PWNO = "123456";
                pb1.PSNO = "122";
                pb1.PPNO = "911";
                pb1.USNO = "1234";
                pb1.NOSA = "XXX";
                pb1.SSMN = "1000";
                PowerBill pb2 = new PowerBill();
                pb2.PNBR = "1234567890";
                pb2.PDTA = "20110713";
                pb2.MNBR = "100";
                pb2.WNBR = "10";
                pb2.USNM = "denver";
                pb2.USAD = "qd";
                pb2.PWNO = "123456";
                pb2.PSNO = "122";
                pb2.PPNO = "911";
                pb2.USNO = "1234";
                pb2.NOSA = "XXX";
                pb2.SSMN = "100,0";
                PowerBill[] pbs = new PowerBill[2] { pb1, pb2 };
                pp.PowerBiLL = pbs;*/


                PowerBill pbTemp = pp.PowerBiLL[(pp.PowerBiLL.Length - 1)];
                if (pp.Status)
                {

                    //充值成功操作                
                    DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), pp.SerialNo,
                        HidCusNo.Value, pp.Message, "1".ToString(), SysCommon.getClientIP(), "0".ToString());

                    Response.Redirect("paysuccess_power.aspx?"
                                                     + "HidMNBR=" + pbTemp.MNBR
                                                    + "&HidNOSA=" + pbTemp.NOSA
                                                    + "&HidPDTA=" + pbTemp.PDTA
                                                    + "&HidPNBR=" + pbTemp.PNBR
                                                    + "&HidPPNO=" + pbTemp.PPNO
                                                    + "&HidPSNO=" + pbTemp.PSNO
                                                    + "&HidPWNO=" + pbTemp.PWNO
                                                    + "&HidSSMN=" + pbTemp.SSMN
                                                    + "&HidUSAD=" + pbTemp.USAD
                                                    + "&HidUSNM=" + pbTemp.USNM
                                                    + "&HidUSNO=" + pbTemp.USNO
                                                    + "&HidWNBR=" + pbTemp.WNBR
                                                    + "&HidCusNo=" + HidCusNo.Value
                                                    + "&HidNowMoney=" + pp.NowMoney
                                                    + "&HidPayMoney=" + pp.PayMoney
                                                    + "&HidPreMoney=" + pp.PreMoney);
                }
                else
                {
                    //充值失败操作                
                    DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), pp.SerialNo,
                        HidCusNo.Value, pp.Message, "2".ToString(), SysCommon.getClientIP(), "0".ToString());

                    LabMessage.Text = "操作失败！原因是：" + pp.Message + "，请稍后重试";
                    PanPay.Visible = false;
                }        
            }       
    }
}
